<template>
	<view class="container">
		<view class="content">
			<view class="search-content">
				<view class="search-item">
					<text class="search-label">题目类型：</text>
					<u-picker :show="isType" :columns="typeOptions" v-model="searchParams.type" @confirm="isTypeConfirm"
						@cancel="isType=false" keyName="label"></u-picker>
					<view class="select-border" @click="isType=true">
						<text v-if="!searchParams.type">请选择题目类型</text>
						<text v-if="searchParams.type" class="selectedTxt">{{searchParams.type}}</text>
					</view>
				</view>
				<view class="search-item">
					<text class="search-label">关键字：</text>
					<u--input placeholder="请输入关键字" shape="circle" v-model="searchParams.stem"></u--input>
				</view>
				<view class="btn-group">
					<u-button text="查询" type="primary" loadingText="查询中" class="search-btn"
						@click="toSearch"></u-button>
				</view>
			</view>
			<view class="btn-group">
				<u-button text="新增单个试题" type="primary" class="create-btn"
					@click="isNewEdit = true;formTitle = 0;"></u-button>
				<u-button text="试题文件导入" type="primary" class="create-btn" @click="isUpload = true"></u-button>
				<u-button text="恢复删除" type="primary" class="create-btn" @click="toUndeletion()"></u-button>
			</view>
			<view v-if="editList.length==0">
				<u-empty mode="list" icon="../../static/listEmpty.png"></u-empty>
			</view>
			<view class="counts" v-if="editList.length!==0">
				<view class="">
					当前共收纳
					<text class="amount">{{ counts.amount }}</text>
					道试题
				</view>
				<view>
					其中单选
					<text class="radio">{{ counts.radio }}</text>
					道、多选
					<text class="multiple">{{ counts.multiple }}</text>
					道、判断
					<text class="judge">{{ counts.judge }}</text>
					道
				</view>
			</view>
			<u-swipe-action v-for="(item,index) in editList" :key="index" autoClose v-if="editList.length!==0">
				<u-swipe-action-item :options="optionsEdit" @click="swipeItem(item,$event)">
					<view class="historicalAchievements_item u-border-bottom">
						<text class="bold">题目类型：</text>
						<text v-if="item.type ==1">单选题</text>
						<text v-if="item.type ==2">多选题</text>
						<text v-if="item.type ==3">判断题</text>
						<view>
							<text class="bold">题干：</text>
							<text>{{item.stem}}</text>
						</view>
						<u-row>
							<u-col span="1.5">
								<text class="bold">选项：</text>
							</u-col>
							<u-col span="10.5">
								<text v-for="(val,key,i) in item.options" :key="i"
									class="layout-start">{{key+'：'+val+' '}} </text>
							</u-col>
						</u-row>
						<view>
							<text class="bold">答案：</text>
							<text v-for="(itm,indx) in item.correctOptions" :key="indx">
								<text v-if="indx">,</text>{{itm}}
							</text>
						</view>
						<view v-if="item.analysis">
							<text class="bold">解析：</text>
							<text>{{item.analysis}}</text>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
			<u-loadmore :status="statusLoading" v-if="editList.length!=0" />
		</view>
		<u-popup :show="isNewEdit" showCancelButton @close="cancelEdit('formDialog')" mode="center"
			:overlayStyle="{'touch-action':'none'}" class="dialog">
			<view class="scroll">
				<view class="popupTitle">{{formTitle == 0 ? '创建试题' : '编辑试题'}}</view>
				<u--form labelPosition="left" :model="formDialog" :rules="rules" ref="formDialog">
					<u-form-item label="对应题库" prop="questionBankId" required>
						<view class="select-border" @click="isFormBank=true">
							<text v-if="!formDialog.questionBankId">请选择对应题库</text>
							<text v-if="formDialog.questionBankId" class="selectedTxt">
								{{formDialog.questionBankId}}
							</text>
						</view>
					</u-form-item>

					<u-form-item label="题目类型" prop="type" required>
						<view class="select-border" @click="isFormType=true">
							<text v-if="!formDialog.type">请选择题目类型</text>
							<text v-if="formDialog.type" class="selectedTxt">{{formDialog.type}}</text>
						</view>
					</u-form-item>
					<u-form-item label="题干" prop="stem" required>
						<u--textarea v-model="formDialog.stem" placeholder="请输入题干"></u--textarea>
					</u-form-item>
					<u-form-item label="选项" prop="options" class="item-options">
						<u-button text="新增" type="primary" @click="onAddOptions()"></u-button>
						<u--input placeholder="请输入内容" v-for="(val, key, i) in formDialog.options" :key="i"
							v-model="formDialog.options[key]" style="margin-top: 10rpx;width: 90%;">
							<u--text :text="key" slot="prefix" margin="0 3px 0 0" type="tips"></u--text>
							<template slot="suffix">
								<view @click="onDelOptions(key, val)">
									<u-icon name="close"></u-icon>
								</view>
							</template>
						</u--input>
					</u-form-item>
					<u-form-item label="正确答案" prop="correctOptions">
						<view v-if="formDialog.type == '单选题' || formDialog.type == '判断题'">
							<u-radio-group v-model="formDialog.correctOptions" placement="column">
								<u-radio :customStyle="{marginBottom: '8px'}"
									v-for="(rval, rkey, i) in formDialog.options" :key="'r-' + i" :label="rkey"
									:name="rkey">
								</u-radio>
							</u-radio-group>
						</view>
						<view v-if="formDialog.type == '多选题'">
							<u-checkbox-group v-model="formDialog.correctOptions" placement="column">
								<u-checkbox :customStyle="{marginBottom: '8px'}"
									v-for="(cval, ckey, i) in formDialog.options" :key="'c-' + i" :label="ckey"
									:name="ckey">
								</u-checkbox>
							</u-checkbox-group>
						</view>
					</u-form-item>
					<u-form-item label="解析" prop="analysis" class="mB80">
						<u--textarea v-model="formDialog.analysis" placeholder="请输入解析"></u--textarea>
					</u-form-item>
				</u--form>
				<view class="btn-group absolutePosition">
					<u-button text="取消" class="reset-btn" @click="cancelEdit('formDialog')"></u-button>
					<u-button text="确认" type="primary" class="search-btn" @click="confirmEdit('formDialog')"></u-button>
				</view>
				<u-picker :show="isFormType" :columns="typeOptions" v-model="formDialog.type"
					@confirm="isFormTypeConfirm" @cancel="isFormType=false" keyName="label"
					class="form-picker"></u-picker>
				<u-picker :show="isFormBank" :columns="bankOptions" v-model="formDialog.questionBankId"
					@confirm="isFormBankConfirm" @cancel="isFormBank=false" keyName="bankName"
					class="form-picker"></u-picker>
			</view>
		</u-popup>
		<u-popup :show="isUpload" showCancelButton @close="cancelEdit('uploadDialog')" mode="center"
			:overlayStyle="{'touch-action':'none'}" class="dialog">
			<view class="scroll scroll-short">
				<view class="popupTitle">导入试题</view>
				<u--form labelPosition="left" :model="uploadDialog" :rules="rules" ref="uploadDialog">
					<u-form-item label="对应题库" prop="questionBankId" required>
						<view class="select-border" @click="isUploadBank=true">
							<text v-if="!uploadDialog.questionBankId">请选择对应题库</text>
							<text v-if="uploadDialog.questionBankId" class="selectedTxt">
								{{uploadDialog.questionBankId}}
							</text>
						</view>
					</u-form-item>
					<u-form-item label="文件上传" prop="">
						<u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
							:maxCount="10" accept="file" previewImage>
						</u-upload>
					</u-form-item>
				</u--form>
				<view class="btn-group absolutePosition">
					<u-button text="取消" class="reset-btn" @click="cancelEdit('uploadDialog')"></u-button>
					<u-button text="确认" type="primary" class="search-btn"
						@click="confirmEdit('uploadDialog')"></u-button>
				</view>
				<u-picker :show="isUploadBank" :columns="bankOptions" v-model="uploadDialog.questionBankId"
					@confirm="isUploadBankConfirm" @cancel="isUploadBank=false" keyName="bankName"
					class="form-picker"></u-picker>
			</view>
		</u-popup>
		<u-popup :show="isPush" showCancelButton @close="cancelEdit('pushDialog')" mode="center"
			:overlayStyle="{'touch-action':'none'}" class="dialog">
			<view class="scroll scroll-short">
				<view class="popupTitle">导入题库</view>
				<u--form labelPosition="left" :model="pushDialog" :rules="rules" ref="pushDialog">
					<u-form-item label="对应题库" prop="questionBankId" required>
						<view class="select-border" @click="isPushBank=true">
							<text v-if="!pushDialog.questionBankId">请选择对应题库</text>
							<text v-if="pushDialog.questionBankId" class="selectedTxt">
								{{pushDialog.questionBankId}}
							</text>
						</view>
					</u-form-item>
				</u--form>
				<view class="btn-group absolutePosition">
					<u-button text="取消" class="reset-btn" @click="cancelEdit('pushDialog')"></u-button>
					<u-button text="确认" type="primary" class="search-btn" @click="confirmEdit('pushDialog')"></u-button>
				</view>
				<u-picker :show="isPushBank" :columns="bankOptions" v-model="pushDialog.questionBankId"
					@confirm="isPushBankConfirm" @cancel="isPushBank=false" keyName="bankName"
					class="form-picker"></u-picker>
			</view>
		</u-popup>
	</view>
</template>

<script>
	import {
		viewBaseBank,
		viewSortBank,
		selectBaseQuestion,
		addBaseQuestion,
		updateQuestion,
		addQuestionToBank,
		delBaseQuestion,
		questionCount,
	} from "../../utils/api.js"
	export default {
		data() {
			return {
				fullHeight: true,
				editList: [],
				total: null, //总条数
				page: 1, //当前页码
				pageSize: 5, //每页显示数量
				// userId: null,
				isType: false,
				typeOptions: [
					[{
							value: 1,
							label: "单选题",
						},
						{
							value: 2,
							label: "多选题",
						},
						{
							value: 3,
							label: "判断题",
						},
					]
				],
				// 查询
				searchParams: {
					type: '',
					stem: '',
				},
				btnSearch: false,
				//仅用于向后端传递数据
				paramsValue: {
					questionBankId: '',
					stem: '',
					type: '',
					pageSize: 5,
					page: 1,
				},
				statusLoading: 'loadmore',
				nextQuery: false,
				onlyReachBottom: true,
				questionBankId: '',
				// 操作
				optionsEdit: [{
					text: '编辑',
					style: {
						backgroundColor: '#3c9cff'
					}
				}, {
					text: '导入题库',
					style: {
						backgroundColor: '#ffaa00'
					}
				}, {
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				// 题库的分类数组 (单个新建、文件导入、单行导入-共用)
				bankOptions: [],
				// 创建/编辑弹窗
				isNewEdit: false,
				formTitle: 0, // 0-创建/1-编辑
				// 编辑题目表单
				formDialog: {
					id: "",
					stem: "",
					options: {},
					correctOptions: [],
					analysis: "",
					type: "",
					questionBankId: "",
					status: 0,
				},
				rules: {
					questionBankId: [{
						required: true,
						message: "请选择对应题库",
						trigger: "change"
					}, ],
					type: [{
						required: true,
						message: "请选择题目类型",
						trigger: "change"
					}, ],
					stem: [{
						required: true,
						message: "请输入题干",
						trigger: "blur"
					}, ],
				},
				isFormType: false,
				isFormBank: false,
				// 上传文件
				isUpload: false,
				uploadDialog: {
					questionBankId: "", //导入id
				},
				isUploadBank: false,
				fileList1: [],
				// 导入题库
				isPush: false,
				pushDialog: {
					questionBankId: "", //导入id
					id: "",
				},
				isPushBank: false,
				// 数量统计
				counts: {},
			}
		},
		onLoad(option) {
			this.getEditList();
			this.getBankOptions();
			this.getCount();
		},
		onReachBottom() {
			if (this.fullHeight) {
				this.fullHeight = false
			}
			if (this.nextQuery) {
				//搜索结果
				++this.paramsValue.page
				this.btnSearch = false
				//获取处理后的查询数据
				const params = this.disposeSearchParams();
				// console.log("const params", params);
				selectBaseQuestion(
					params
				).then(s => {
					// console.log("查询s", s);
					if (s.code === 20000) {
						this.editList = this.editList.concat(s.data.records)
						// console.log("this.editList onreachbooon 查询", this.editList);
						this.onlyReachBottom = false
						//所有数据加载完
						if (s.data.total == this.editList.length) {
							this.statusLoading = 'nomore'
							this.nextQuery = false
							// console.log("s.data.total==this.editList.length");
						}
					} else {
						uni.showToast({
							title: s.message,
							icon: 'none'
						})
					}
				})
			} else if (this.onlyReachBottom) {
				// console.log("this.page * this.pageSize < this.total", this.page * this.pageSize < this.total);
				// console.log("1", this.page, this.pageSize, this.total);
				if (this.page * this.pageSize < this.total) {
					this.statusLoading = 'loading'
					this.page++
					this.getEditList()
					console.log("onReachBottom");
				} else {
					this.statusLoading = 'nomore'

				}
			} else {
				console.log("什么也不做");
			}
		},
		computed: {
			containHeight() {
				return this.fullHeight ? {
					height: 'calc(100vh - 44px)'
				} : {
					height: '100%'
				}
			},
		},
		methods: {
			// 获取题库数据
			getBankOptions() {
				viewSortBank().then(s => {
					if (s.code === 20000) {
						// console.log("getBankOptions", s.data);
						this.bankOptions = [s.data];
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			// 获取题目列表
			getEditList(isdel) {
				viewBaseBank({
					pageSize: this.pageSize,
					page: this.page,
				}).then(s => {
					if (s.code === 20000) {
						// console.log("viewBaseBank",s.data.records);
						// console.log("isdel", isdel, "isdel==ture", isdel == 'ture');
						// if (isdel == 'ture') {
						// 	//删除操作
						// 	this.editList = s.data.records
						// } else {
						// 	this.editList = this.editList.concat(s.data.records)
						// }
						this.editList = this.editList.concat(s.data.records)
						// this.editList = s.data.records
						this.total = s.data.total
						if (this.total < this.pageSize) {
							this.statusLoading = 'nomore'
						}
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			getCount() {
				questionCount().then(s => {
					if (s.code == 20000) {
						this.counts = s.data;
					} else {
						uni.showToast({
							title: s.message,
							icon: 'none'
						})
					}
				})
			},
			// 确定题目类型
			isTypeConfirm(val) {
				this.isType = false
				this.searchParams.type = val.value[0].label
			},
			//处理参数向后端查询数据
			disposeSearchParams() {
				// 选中后值变成了文字,要变成数字
				const curType = this.typeOptions[0].find(array => array.label == this.searchParams.type);
				if (curType) {
					this.paramsValue.type = curType.value;
				}
				this.paramsValue.stem = this.searchParams.stem
				// this.paramsValue.questionBankId = this.questionBankId
				//过滤空的参数
				const params = Object.keys(this.paramsValue).filter((key) => this.paramsValue[key] !== null && this
					.paramsValue[key] !== '' && this.paramsValue[key] !== undefined).reduce((acc, key) => ({
					...acc,
					[key]: this.paramsValue[key]
				}), {})
				// console.log("const params", params);
				return params;
			},
			// 查询 selectBaseQuestion
			toSearch() {
				this.paramsValue.page = 1
				this.btnSearch = true
				this.onlyReachBottom = false
				this.editList = []
				//获取处理后的查询数据
				const params = this.disposeSearchParams();
				selectBaseQuestion(
					params
				).then(s => {
					// console.log("查询s", s);
					if (s.code === 20000) {
						//搜索结果反映到视图
						// console.log("selectBaseQuestion", s.data);
						this.btnSearch = false
						this.editList = s.data.records
						this.nextQuery = true
						// this.searchList = this.searchList.concat(s.data.data)
						//查询结果的页数,向上取整
						let searchPageNum = Math.ceil(s.data.total / this.pageSize)
						this.page = 1
						if (searchPageNum > this.page) {
							//调查询接口，页码加1							
							this.statusLoading = 'loading'
							console.log("还有下一页");
						} else {
							this.statusLoading = 'nomore'
							console.log("只有当前页");
						}

					} else {
						uni.showToast({
							title: s.message,
							icon: 'none'
						})
					}
				})
			},
			// 滑动当前题目
			swipeItem(item, e) {
				// console.log("swipeItem e", e);
				// console.log("item", item);
				if (e.index == 0) {
					//编辑
					this.isNewEdit = true
					this.formTitle = 1
					// console.log(item);
					// 从后端拿到的是数字,要转成文字
					const curType = this.typeOptions[0].find(array => array.value == item.type);
					if (curType) {
						item.type = curType.label;
					}
					const curBankId = this.bankOptions[0].find(array => array.id == item.questionBankId);
					if (curBankId) {
						item.questionBankId = curBankId.bankName;
					}
					this.formDialog = item
					// 单选、判断- 拿到数组转字符串
					if (this.formDialog.type == '单选题' || this.formDialog.type == '判断题') {
						this.formDialog.correctOptions = this.formDialog.correctOptions[0];
					}
					// console.log("this.formDialog", this.formDialog);
				} else if (e.index == 1) {
					this.isPush = true
					this.pushDialog.id = item.id
				} else if (e.index == 2) {
					//删除
					let that = this
					uni.showModal({
						title: '提示',
						content: '此操作将永久删除该题目, 是否继续?',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								delBaseQuestion({
									id: item.id
								}).then(s => {
									if (s.code === 20000) {
										uni.showToast({
											title: '删除成功',
											icon: 'success'
										})
										that.page = 1
										that.editList = []
										that.getEditList('ture')
										that.$forceUpdate()
									} else {
										uni.showToast({
											title: s.message,
											icon: 'none'
										})
									}
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					});
				} else {}
			},
			// 表单的类型弹窗点击确认
			isFormTypeConfirm(val) {
				// console.log("val", val.value[0]);
				this.isFormType = false
				//改变题目类型，正确答案重新置空
				if (val.value[0].value == 2) {
					this.formDialog.correctOptions = []
				} else {
					this.formDialog.correctOptions = ""
				}
				this.formDialog.type = val.value[0].label
				// console.log("this.formDialog.type", this.formDialog.type);
			},
			// 表单的对应题库弹窗点击确认
			isFormBankConfirm(val) {
				this.isFormBank = false
				this.formDialog.questionBankId = val.value[0].bankName
			},
			// 新增选项
			onAddOptions() {
				const az = [...Array(5).keys()].map((i) => String.fromCharCode(i + 65)); //A-Z
				const last = Object.keys(this.formDialog.options).pop();
				let next = az[az.indexOf(last) + 1];
				if(next){
					this.$set(this.formDialog.options, next, "");
				}				
				// console.log("this.formDialog.options", this.formDialog.options);
			},
			// 删除选项
			onDelOptions(key, val) {
				// 直接删除当前选项
				let obj = JSON.parse(JSON.stringify(this.formDialog.options));
				delete obj[key];
				// 重新排序
				const az = [...Array(26).keys()].map((i) => String.fromCharCode(i + 65)); //A-Z
				let values = Object.values(obj);
				let orderObj = {};
				values.forEach((item, index) => {
					orderObj[az[index]] = item;
				});
				this.formDialog.options = orderObj;
			},
			// 确认编辑
			confirmEdit(formName) {
				this.$refs[formName].validate().then(res => {
					// console.log("confirmEdit", this.formDialog);
					if (res) {
						// uni.$u.toast('校验通过')
						if (formName == "formDialog") {
							this.limitLength();
						} else if (formName == "uploadDialog") {
							this.onImport();
						} else if (formName == "pushDialog") {
							this.pushBank();
						}
					}
				}).catch(errors => {
					console.log(errors);
					uni.$u.toast('校验失败')
				})
			},
			// 限制选项的长度
			limitLength() {
				let optsLength = Object.keys(this.formDialog.options).length;
				let cursLength = this.formDialog.correctOptions.length;
				// console.log("optsLength", optsLength);
				// console.log("cursLength", cursLength);
				if (this.formDialog.type == '单选题') {
					if (optsLength < 2) {
						uni.$u.toast('单选题最少设置2个选项')
					} else if (optsLength > 5) {
						uni.$u.toast('单选题最多设置5个选项')
					} else if (cursLength == 0) {
						uni.$u.toast('请选择正确选项')
					} else {
						this.validSubmit();
					}
				} else if (this.formDialog.type == '多选题') {
					if (optsLength < 3) {
						uni.$u.toast('多选题最少设置3个选项')
					} else if (optsLength > 5) {
						uni.$u.toast('多选题最多设置5个选项')
					} else if (cursLength < 2) {
						uni.$u.toast('请至少设置两个正确选项')
					} else {
						this.validSubmit();
					}
				} else if (this.formDialog.type == '判断题') {
					if (optsLength !== 2) {
						uni.$u.toast('判断题只能设置两个选项')
					} else if (cursLength == 0) {
						uni.$u.toast('请选择正确选项')
					} else {
						this.validSubmit();
					}
				}
			},
			// 取消编辑，置空
			cancelEdit(formName) {
				// console.log(formName);
				if (formName == "formDialog") {
					this.isNewEdit = false
					this.formDialog = {
						id: "",
						stem: "",
						options: {},
						correctOptions: [],
						analysis: "",
						type: "",
						questionBankId: "",
						status: 0,
					};
				} else if (formName == "uploadDialog") {
					this.isUpload = false
					this.uploadDialog = {
						questionBankId: "",
					}
				} else if (formName == "pushDialog") {
					this.isPush = false
					this.pushDialog = {
						questionBankId: "",
						id: "",
					}
				}
			},
			// 正确的提交
			validSubmit() {
				let data = JSON.parse(JSON.stringify(this.formDialog));
				// 提交前-1.类型和题库:文字换成数字 2.单选题判断题的正确答案转成数组
				const curType = this.typeOptions[0].find(array => array.label == data.type);
				if (curType) {
					data.type = curType.value;
				}
				const curBankId = this.bankOptions[0].find(array => array.bankName == data.questionBankId);
				if (curBankId) {
					data.questionBankId = curBankId.id;
				}
				if (data.type == 1 || data.type == 3) {
					let arr = [];
					arr.push(data.correctOptions);
					data.correctOptions = arr;
				}
				console.log("validSubmit", data);
				if (this.formTitle == 0) {
					delete data["id"];
					addBaseQuestion(data).then(s => {
						if (s.code === 20000) {
							uni.showToast({
								title: '添加成功',
								icon: "success"
							})
							this.cancelEdit("formDialog")
							this.page = 1
							this.editList = []
							this.getEditList()
						} else {
							uni.showToast({
								title: s.message,
								icon: "none"
							})
						}
					})

				} else {
					updateQuestion(data).then(s => {
						if (s.code === 20000) {
							uni.showToast({
								title: '更新成功',
								icon: "success"
							})
							this.cancelEdit("formDialog")
							this.getEditList()
						} else {
							uni.showToast({
								title: s.message,
								icon: "none"
							})
						}
					})
				}
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			afterRead(event) {
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file) //新增的文件
				lists.map((item) => {
					if (!/\.(xlsx|xls|XLSX|XLS)$/.test(item.name)) {
						setTimeout(() => {
							uni.$u.toast('上传文件只能为excel文件，且为xlsx,xls格式')
						}, 100);
					} else {
						this[`fileList${event.name}`].push({
							...item,
						})
					}
				})
			},
			isUploadBankConfirm(val) {
				this.isUploadBank = false
				this.uploadDialog.questionBankId = val.value[0].bankName
			},
			// 文件导入
			onImport() {
				// console.log("导入");
				// console.log(this.fileList1);
				let data = JSON.parse(JSON.stringify(this.uploadDialog));
				const curBankId = this.bankOptions[0].find(array => array.bankName == data.questionBankId);
				if (curBankId) {
					data.questionBankId = curBankId.id;
				}
				this.fileList1.forEach((e) => {
					// console.log(e.raw);
					const getBaseUrl = uni.getStorageSync('netVal');
					uni.uploadFile({
						url: getBaseUrl+'/jqmk/questionbank/importQuestionBank', // 接口地址
						filePath: e.url,
						name: 'file',
						formData: {
							questionBankId: data.questionBankId
						},
						headers: {
							"Content-Type": "multipart/form-data"
						},
						success: (res) => {
							let s = JSON.parse(res.data)
							this.cancelEdit("uploadDialog")
							if (s.code == 20000) {
								uni.$u.toast(s.message)
								this.fileList1 = []
							}
						}
					});
				})
			},

			isPushBankConfirm(val) {
				this.isPushBank = false
				this.pushDialog.questionBankId = val.value[0].bankName
			},
			// 导入对应题库
			pushBank() {
				let data = JSON.parse(JSON.stringify(this.pushDialog));
				const curBankId = this.bankOptions[0].find(array => array.bankName == data.questionBankId);
				if (curBankId) {
					data.questionBankId = curBankId.id;
				}
				// console.log(data);
				addQuestionToBank(data).then(s => {
					if (s.code === 20000) {
						uni.showToast({
							title: '导入成功',
							icon: "success"
						})
						this.cancelEdit("pushDialog")
					} else {
						uni.showToast({
							title: s.message,
							icon: "none"
						})
					}
				})
			},
			// 恢复删除页面跳转
			toUndeletion() {
				uni.navigateTo({
					url: "/pages/bank/recycleBin"
				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.container {
		// background: url("../../static/bg.png");
		// background-size: cover;	
		background: linear-gradient(#5191FF 5%, #6AA2FF 8%, #BDD7FE 15%, #F6FAFF 100%);
		padding: 30rpx 30rpx;
		width: 100%;
		position: relative;
		box-sizing: border-box;
		// height: calc(100vh - 44px - 50px);

		.content {
			background: #ffffff;
			// margin-top: 30rpx;
			padding: 30rpx 32rpx 2rpx;
			box-sizing: border-box;
			border-radius: 15rpx;
			opacity: 0.9;
			width: 100%;
			position: relative;

			// 查询部分
			.search-content {
				box-sizing: border-box;
				padding: 0rpx 15rpx;
				width: 100%;
				position: relative;
				background: #ffffff;

				.search-item {
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 100%;
					margin-top: 10rpx;
					font-size: 30rpx;
					box-sizing: border-box;
					padding: 10rpx 20rpx;

					.search-label {
						max-width: 300rpx;
						overflow: hidden;
						// text-overflow: ellipsis;
						white-space: nowrap;
						font-size: 30rpx;
					}

					.select-border {
						width: 80%;
						height: 38px;
						line-height: 38px;
						border: 1px solid #dadbde;
						border-radius: 50rpx;
						color: #B1B1B1;
						box-sizing: border-box;
						padding: 0rpx 25rpx;
						font-size: 16px;
						// z-index: 0;

						.selectedTxt {
							color: rgb(48, 49, 51);
						}
					}

					.select-border-has {
						width: 80%;
						height: 38px;
						line-height: 38px;
						border: 1px solid #dadbde;
						border-radius: 50rpx;
						// color: #B1B1B1;
						box-sizing: border-box;
						padding: 0rpx 25rpx;
						font-size: 16px;
						// z-index: 9;
						position: relative;
						display: flex;
						align-items: center;

						.selectedTxt {
							color: rgb(48, 49, 51);
						}
					}
				}


			}

			.counts {
				padding: 30rpx 30rpx 0;
				font-size: 30rpx;
				text-align: center;

				.amount {
					color: #ee6666;
				}

				.radio {
					color: #5470c6;
				}

				.multiple {
					color: #91cc75;
				}

				.judge {
					color: #fac858;
				}
			}

			// 题目滑块部分
			/deep/.u-swipe-action-item__right {
				position: absolute;
				top: 1px;
				bottom: 1px;
				right: 1px;
			}

			.historicalAchievements_item {
				background: #ffffff;
				box-sizing: border-box;
				padding: 30rpx;

				// margin: 40rpx 0rpx;
				// border-radius: 20rpx;
				// box-shadow: 4px 4px 10px #888888;
				.bold {
					font-weight: 700;
					white-space: nowrap;
					line-height: 1.6;
				}

				.testPaperTitle {
					font-size: 28rpx;
					color: #000000;
					font-weight: bold;
				}

				.testTime {
					font-size: 28rpx;
					color: #737375;
					margin-top: 10rpx;
				}

				.line {
					height: 1rpx;
					background: #737375;
					width: 100%;
					margin: 30rpx 0rpx;
				}

				.historical_content {
					.historical_item {
						width: 100%;
						display: flex;
						justify-content: space-between;

						.historical_title {
							font-size: 30rpx;
							color: #737375;
						}

						.historical_txt {
							margin-top: 10rpx;
							font-size: 30rpx;
							color: #0B0B0B;
						}

						.bule {
							color: #3888FF;
							font-size: 32rpx;
						}
					}
				}
			}


		}
	}

	.btn-group {
		display: flex;
		margin-top: 40rpx;
		width: 100%;
		position: relative;
		justify-content: space-between;

		.search-btn {
			width: 40%;
			border-radius: 100rpx;
			background: linear-gradient(to right, #7774ff, #017ffd, #01b1fd);
			color: #fff;
		}

		.reset-btn {
			width: 40%;
			border-radius: 100rpx;
		}

		.create-btn {
			width: 30%;
		}
	}

	.dialog {
		/deep/.u-popup__content {
			width: 90%;
			position: relative;
			padding: 40rpx;
			box-sizing: border-box;
			overflow: auto;
		}



		.scroll {
			height: 1200rpx; // 固定高度
			overflow-y: scroll; // 超出滚动
			overscroll-behavior: none; // 禁止滚动溢出

			.popupTitle {
				font-weight: 900;
				white-space: nowrap;
				line-height: 1.6;
				text-align: center;
				position: -webkit-sticky;
				position: sticky;
				top: 0;
				z-index: 2;
				background: #ffffff;

			}

			/deep/.u-form {
				.u-form-item {
					.u-form-item__body__left {
						align-items: flex-start;
					}
				}

				.item-options {
					.u-form-item__body__right__content__slot {
						flex-direction: column;
						align-items: flex-start;
					}
				}

				.select-border {
					width: 80%;
					height: 38px;
					line-height: 38px;
					border: 1px solid #dadbde;
					border-radius: 50rpx;
					color: #B1B1B1;
					box-sizing: border-box;
					padding: 0rpx 25rpx;
					font-size: 16px;
					// z-index: 0;

					.selectedTxt {
						color: rgb(48, 49, 51);
					}
				}
			}

			.mB80 {
				margin-bottom: 80rpx;
			}

			.absolutePosition {
				position: absolute;
				bottom: 0;
				left: 0;
				width: 100%;
				background-color: #ffffff;
				margin: 0rpx 0rpx 20rpx 0rpx;
				box-sizing: border-box;
				padding-top: 20rpx;
			}
		}

		.scroll-short {
			height: 600rpx;
		}
	}

	.form-picker {
		/deep/.u-popup__content {
			width: 100%;
			padding: 0;
		}
	}

	// .medal {
	// 	width: 50rpx;
	// 	height: 50rpx;
	// 	margin-left: 20rpx;
	// }

	// .warnTxt {
	// 	color: #E13124 !important;
	// 	font-size: 30rpx !important;
	// }

	// .dateBorder {
	// 	width: 80%;
	// 	height: 38px;
	// 	border: 1px solid #dadbde;
	// 	border-radius: 50rpx;
	// 	box-sizing: border-box;
	// 	padding: 0rpx 25rpx;
	// 	font-size: 16px;
	// 	z-index: 1;
	// }



	// /deep/.u-modal__content{
	// 	overflow: auto;
	// }
</style>